from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-02-04 14:13:00.399308
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Thu, 04, Feb, 2021
Time: 14:13:05
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -42.4807
Nobs: 215.000 HQIC: -43.3216
Log likelihood: 2062.71 FPE: 8.67663e-20
AIC: -43.8917 Det(Omega_mle): 5.76308e-20
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.539595 0.144065 3.745 0.000
L1.Burgenland 0.018844 0.067256 0.280 0.779
L1.Kärnten -0.276430 0.050695 -5.453 0.000
L1.Niederösterreich 0.049891 0.109636 0.455 0.649
L1.Oberösterreich 0.294347 0.137242 2.145 0.032
L1.Salzburg 0.208808 0.074267 2.812 0.005
L1.Steiermark 0.151216 0.100095 1.511 0.131
L1.Tirol 0.068945 0.066678 1.034 0.301
L1.Vorarlberg -0.020291 0.039601 -0.512 0.608
L1.Wien -0.017625 0.134174 -0.131 0.895
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.569047 0.200479 2.838 0.005
L1.Burgenland 0.083953 0.093593 0.897 0.370
L1.Kärnten 0.179163 0.070547 2.540 0.011
L1.Niederösterreich -0.038449 0.152569 -0.252 0.801
L1.Oberösterreich 0.244526 0.190984 1.280 0.200
L1.Salzburg 0.133595 0.103349 1.293 0.196
L1.Steiermark 0.031853 0.139291 0.229 0.819
L1.Tirol 0.208431 0.092788 2.246 0.025
L1.Vorarlberg -0.032393 0.055108 -0.588 0.557
L1.Wien -0.357671 0.186716 -1.916 0.055
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.317409 0.091996 3.450 0.001
L1.Burgenland 0.092307 0.042948 2.149 0.032
L1.Kärnten -0.058854 0.032373 -1.818 0.069
L1.Niederösterreich 0.280054 0.070011 4.000 0.000
L1.Oberösterreich 0.183660 0.087639 2.096 0.036
L1.Salzburg 0.047574 0.047425 1.003 0.316
L1.Steiermark 0.011515 0.063918 0.180 0.857
L1.Tirol 0.051350 0.042579 1.206 0.228
L1.Vorarlberg 0.000621 0.025288 0.025 0.980
L1.Wien 0.083424 0.085680 0.974 0.330
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.281805 0.068730 4.100 0.000
L1.Burgenland 0.004238 0.032087 0.132 0.895
L1.Kärnten 0.041387 0.024186 1.711 0.087
L1.Niederösterreich 0.016620 0.052305 0.318 0.751
L1.Oberösterreich 0.415446 0.065475 6.345 0.000
L1.Salzburg 0.036198 0.035431 1.022 0.307
L1.Steiermark 0.212000 0.047753 4.440 0.000
L1.Tirol 0.047778 0.031811 1.502 0.133
L1.Vorarlberg -0.009036 0.018893 -0.478 0.632
L1.Wien -0.048876 0.064012 -0.764 0.445
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.573203 0.142464 4.023 0.000
L1.Burgenland -0.031531 0.066509 -0.474 0.635
L1.Kärnten -0.006392 0.050132 -0.128 0.899
L1.Niederösterreich -0.007567 0.108418 -0.070 0.944
L1.Oberösterreich 0.257137 0.135717 1.895 0.058
L1.Salzburg 0.130302 0.073442 1.774 0.076
L1.Steiermark 0.033405 0.098983 0.337 0.736
L1.Tirol 0.116611 0.065937 1.769 0.077
L1.Vorarlberg 0.118858 0.039161 3.035 0.002
L1.Wien -0.169494 0.132684 -1.277 0.201
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.210700 0.100872 2.089 0.037
L1.Burgenland 0.051197 0.047092 1.087 0.277
L1.Kärnten -0.010850 0.035496 -0.306 0.760
L1.Niederösterreich -0.013212 0.076766 -0.172 0.863
L1.Oberösterreich 0.362643 0.096095 3.774 0.000
L1.Salzburg 0.001664 0.052000 0.032 0.974
L1.Steiermark 0.008933 0.070085 0.127 0.899
L1.Tirol 0.120226 0.046687 2.575 0.010
L1.Vorarlberg 0.064620 0.027728 2.330 0.020
L1.Wien 0.212429 0.093947 2.261 0.024
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.424437 0.138126 3.073 0.002
L1.Burgenland 0.092263 0.064484 1.431 0.152
L1.Kärnten 0.120289 0.048605 2.475 0.013
L1.Niederösterreich 0.071223 0.105116 0.678 0.498
L1.Oberösterreich -0.137366 0.131584 -1.044 0.297
L1.Salzburg -0.034157 0.071205 -0.480 0.631
L1.Steiermark 0.419764 0.095968 4.374 0.000
L1.Tirol 0.410464 0.063929 6.421 0.000
L1.Vorarlberg 0.060127 0.037968 1.584 0.113
L1.Wien -0.425509 0.128643 -3.308 0.001
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.364770 0.243274 1.499 0.134
L1.Burgenland -0.093242 0.113572 -0.821 0.412
L1.Kärnten -0.217534 0.085606 -2.541 0.011
L1.Niederösterreich 0.076292 0.185136 0.412 0.680
L1.Oberösterreich 0.455315 0.231752 1.965 0.049
L1.Salzburg 0.123421 0.125410 0.984 0.325
L1.Steiermark -0.113781 0.169024 -0.673 0.501
L1.Tirol 0.354037 0.112595 3.144 0.002
L1.Vorarlberg -0.037006 0.066872 -0.553 0.580
L1.Wien 0.122878 0.226572 0.542 0.588
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.593537 0.078041 7.605 0.000
L1.Burgenland -0.017915 0.036433 -0.492 0.623
L1.Kärnten -0.021011 0.027462 -0.765 0.444
L1.Niederösterreich -0.045898 0.059391 -0.773 0.440
L1.Oberösterreich 0.220127 0.074345 2.961 0.003
L1.Salzburg 0.024883 0.040231 0.619 0.536
L1.Steiermark 0.108954 0.054222 2.009 0.044
L1.Tirol 0.072666 0.036120 2.012 0.044
L1.Vorarlberg 0.060259 0.021452 2.809 0.005
L1.Wien 0.009143 0.072683 0.126 0.900
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.169016 0.101552 0.172808 0.308871 0.107102 0.108663 -0.018411 0.166539
Kärnten 0.169016 1.000000 0.022325 0.193903 0.143282 -0.118724 0.073912 0.047863 0.163190
Niederösterreich 0.101552 0.022325 1.000000 0.199017 0.118361 0.197857 0.249233 0.108615 0.354443
Oberösterreich 0.172808 0.193903 0.199017 1.000000 0.197403 0.246261 0.183130 0.040221 0.168753
Salzburg 0.308871 0.143282 0.118361 0.197403 1.000000 0.189291 0.080141 0.152785 -0.039729
Steiermark 0.107102 -0.118724 0.197857 0.246261 0.189291 1.000000 0.149284 0.074741 0.021575
Tirol 0.108663 0.073912 0.249233 0.183130 0.080141 0.149284 1.000000 0.114152 0.194098
Vorarlberg -0.018411 0.047863 0.108615 0.040221 0.152785 0.074741 0.114152 1.000000 0.055408
Wien 0.166539 0.163190 0.354443 0.168753 -0.039729 0.021575 0.194098 0.055408 1.000000